package com.cast.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cast.health.entity.Result;
import com.cast.health.mapper.CheckGroupMapper;
import com.cast.health.mapper.CheckItemMapper;
import com.cast.health.pojo.CheckGroup;
import com.cast.health.pojo.CheckItem;
import com.cast.health.service.CheckGroupService;
import com.cast.health.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {

    @Autowired
    private CheckItemMapper mapper;

    /**
     * 删除检查项
     *
     * 注意:以为两张表存在中间表是连接,所以要删除被包含的类
     * 需要先删除中间表的联系
     *
     * @param id
     */
    @Override
    public boolean deleteCheckItem(Integer id) {
        //1.先根据id先删除中间表的数据
        int i = mapper.deleteCheckGroupAndCheckItem(id);
        //2.判断是否删除
        if (i<=0){
            return false;
        }
        //3.再删除检查组的基本信息:调用service删除该id在CheckItem表中的对象
        int i1 = mapper.deleteCheckItem(id);
        if (i1<=0){
            return false;
        }
        return true;
    }
}
